package com.simple.piger.controller;

import com.simple.piger.utils.AjaxResult;
import com.simple.piger.utils.DingTalk;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author baolw
 */
@RestController
@RequestMapping("/test/error")
public class TestController extends BaseController {
    @Autowired
    private DingTalk dingTalk;

    @GetMapping("/info")
    public AjaxResult testError(@RequestParam("type") String type) {

        try {
            Double.valueOf("sdfsd");
        } catch (Exception e) {
            if ("action".equals(type)) {
                dingTalk.sendException(e);
            } else if ("markdown".equals(type)) {
                dingTalk.sendMarkdownException(e);
            } else {
                dingTalk.sendException(e);
            }

        }
        return success();
    }
}
